<?php

//Rquire MySqlAdapter.
require_once(dirname(__FILE__).'/../db/MySqlAdapter.php');

class studentsDBHandler {

 	/*************************************************************************
	*************************      Public Methods     ************************
	*************************************************************************/
	
		//This function returns a table with student details 
		public static function find_student($student_id,$selected)
		{
			return studentsDBHandler::studentDetails($student_id,$selected);
		}
		
		//This function adds new student to tables
		public static function manage_student($student_object)
		{
			return studentsDBHandler::manageStudent($student_object);
		}
	
	/*****************       Private Methods        *******************/

	private static function studentDetails($student_id,$selected) {
		 $mysql_link = MySqlAdapter::get_mysql_link();
		 
		 $query = studentsDBHandler::find_student_details($student_id,$selected);
		 $result = mysql_query($query, $mysql_link);	//Excecute the Query
		 
		return $result;
	}
	
	private static function manageStudent($student_object) {
		 $mysql_link = MySqlAdapter::get_mysql_link();
		 $query = studentsDBHandler::manage_student_details($student_object);
		 $result = mysql_query($query, $mysql_link);	//Excecute the Query
		 
		return $result;
	}
	/*************************************************************************
	*************************   Queires Methods   ****************************
	*************************************************************************/

	private static function find_student_details($student_id,$selected)	
	{
		switch($selected)
		{
			case 0: 
					$query=
					"SELECT *
					 FROM `ohel_shelomo_2012`.`person` 
					 WHERE id=".$student_id;
					break;
			case 1:
					$query=
					"SELECT *
					 FROM `ohel_shelomo_2012`.`students` 
					 WHERE id=".$student_id;
					break;
			
		}
		return $query;
	}
	
	private static function manage_student_details($student_object)
	{	
	$select=$student_object->select;
	switch ($select){
		case 2:
				$query=
				"INSERT INTO `ohel_shelomo_2012`.`person` (`id`, `first_name`, `last_name`, `adress`, `phone`, `email`, `type`) VALUES ('".$student_object->id."', '".$student_object->first_name."', '".$student_object->last_name."', '".$student_object->adress."', '".$student_object->phone."', '".$student_object->email."', 'student')";
				break;
	case 3: 
		$query="DELETE FROM `ohel_shelomo_2012`.`person` WHERE `person`.`id` = ".$student_object->id;
		break;
	case 4: 
		$query="UPDATE  `ohel_shelomo_2012`.`person` SET  `".$student_object->optionToUpdate."` =  '".$student_object->valueToUpdate."',
`type` =  'student' WHERE  `person`.`id` =".$student_object->id;
;
		break;
	}
	
	return $query;
					
	}
}
?>